home *** CD-ROM | disk | FTP | other *** search
/ CD World Haziran 1997 / CD World Haziran 1997.iso / Cesitlemeler / Directx 3.0 / dx3.exe / SDK / SAMPLES / IKLOWNS / CGSPRITE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  3.8 KB  |  146 lines

  1. /*===========================================================================*\
  2. |
  3. |  File:        cgsprite.h
  4. |
  5. |  Description: 
  6. |       
  7. |-----------------------------------------------------------------------------
  8. |
  9. |  Copyright (C) 1995-1996 Microsoft Corporation.  All Rights Reserved.
  10. |
  11. |  Written by Moss Bay Engineering, Inc. under contract to Microsoft Corporation
  12. |
  13. \*===========================================================================*/
  14.  
  15. /**************************************************************************
  16.  
  17.     (C) Copyright 1995-1996 Microsoft Corp.  All rights reserved.
  18.  
  19.     You have a royalty-free right to use, modify, reproduce and 
  20.     distribute the Sample Files (and/or any modified version) in 
  21.     any way you find useful, provided that you agree that 
  22.     Microsoft has no warranty obligations or liability for any 
  23.     Sample Application Files which are modified. 
  24.  
  25.     we do not recomend you base your game on IKlowns, start with one of
  26.     the other simpler sample apps in the GDK
  27.  
  28.  **************************************************************************/
  29.  
  30. #ifndef CGSPRITE_H
  31. #define CGSPRITE_H
  32.  
  33. #include <linklist.h>
  34. #include "cgbitbuf.h"
  35.  
  36. struct SpriteRenderInfo
  37. {
  38.     CGameBitBuffer* mpBits;     // image bits
  39.     int mSrcX;
  40.     int mSrcY;
  41.     int mWidth;
  42.     int mHeight;
  43.  
  44.     BOOL mRevX;
  45.     BOOL mRevY;
  46.  
  47.     BOOL mNewBits;      // flag that mpBits needs deleted
  48. };
  49.  
  50. #define SRI_NORMAL 0
  51. #define SRI_HORZMIRROR 1
  52. #define SRI_VERTMIRROR 2
  53. #define SRI_BOTHMIRROR 3
  54.  
  55. #define SRI_INFOCOUNT 4
  56.  
  57. struct CGameSprite
  58. {
  59.     CGameSprite(
  60.         char* pFileName,
  61.         char* pSpriteName,
  62.         CGameBitBuffer* pBits,
  63.         BOOL needHorzMirror = FALSE,
  64.         BOOL needVertMirror = FALSE
  65.         );
  66.     virtual ~CGameSprite();
  67.  
  68.     SpriteRenderInfo mInfo[SRI_INFOCOUNT];
  69. };
  70.  
  71. class CGameSpriteBuffer
  72. {
  73. public:
  74.     CGameSpriteBuffer( char* pFileName );
  75.     virtual ~CGameSpriteBuffer();
  76.  
  77.     char* mpFileName;
  78.     CGameBitBuffer* mpBitBuffer;        // a single DIB containing sprites
  79.     int mRefCount;              // for knowing when to remove a buffer
  80.  
  81. private:
  82.     void SprToBmp(char* pSprName,char* pOutBuffer,int size);
  83. };
  84.  
  85. class CGameScreen;
  86. class CGameUpdateList;
  87.  
  88. class CGameSpriteSequence
  89. {
  90. public:
  91.     CGameSpriteSequence(
  92.         char* pFileName,
  93.         char* pSequenceName,
  94.         int rate,
  95.         BOOL needHorzMirror = FALSE,
  96.         BOOL needVertMirror = FALSE
  97.         );
  98.  
  99.     virtual ~CGameSpriteSequence();
  100.  
  101.     virtual BOOL Frame();
  102.     virtual void Render(
  103.             CGameScreen* pScreen,
  104.             int x,
  105.             int y,
  106.             BOOL revX,
  107.             BOOL revY,
  108.             LPRECT pDirty
  109.             );
  110.     virtual int GetCurWidth()
  111.     {
  112.         return mpSpriteArray[mCurSprite]->mInfo[0].mWidth;
  113.     }
  114.     virtual int GetCurHeight()
  115.     {
  116.         return mpSpriteArray[mCurSprite]->mInfo[0].mHeight;
  117.     }
  118.  
  119.     virtual int NextSprite(int time, BOOL wrap=TRUE);
  120.  
  121.     void SetCurSprite( int sprite )
  122.     {
  123.         mCurSprite = sprite;
  124.         mLastTime = -1;
  125.     }
  126.  
  127. protected:
  128.     static LinkedList* mpBufferList;    // list of CGameSpriteBuffers containing all sprites
  129.  
  130.     CGameSprite** mpSpriteArray;        // sprites for this sequence
  131.     int mNumSprites;            // size of the array
  132.     int mCurSprite;             // which sprite is in the current frame
  133.     int mPeriod;                // number of time slices per frame
  134.     int mLastTime;              // last time we changed frames
  135.  
  136.     CGameSpriteBuffer* mpMyBuffer;      // bit buffer for this instance's sprites
  137.  
  138.     // return a ptr to the sprite buffer corresponding .spr filename
  139.     CGameSpriteBuffer* LoadSpriteBits( char* pFileName );
  140.  
  141.     // decrement reference count & delete buffer if 0
  142.     void UnloadSpriteBits();
  143. };
  144.  
  145. #endif // CGSPRITE_H
  146.